package com.example.sls.controller.teacher.proSet;

import com.example.sls.pojo.teacher.proSet.ProSet;
import com.example.sls.service.teacher.proSet.ProSetService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/proSet")
public class ProSetController {

    @Autowired
    private ProSetService proSetService;

    @PostMapping("/addProSet")
    public Map<String,String> addProSet(@RequestParam Map<String,String> params){
        Map<String,String> res = new HashMap<>();

        Integer setId = Integer.valueOf(params.get("setId"));
        Integer createdBy = Integer.valueOf(params.get("createdBy"));

//        System.out.println("========");
//        System.out.println("setId: " + setId);
//        System.out.println("createdBy: " + createdBy);
//        System.out.println("========");

        if(proSetService.getProSetBySetId(setId) != null){  //如果当前setId存在
            res.put("error_message", "当前setId已存在");
            return res;
        }

        if(proSetService.addProSet(setId,createdBy)){
            res.put("error_message", "success");
        }
        else{
            res.put("error_message", "failed");
        }
        return res;
    }

    //通过teacherId分页获取该老师的所有题集
    @GetMapping("/getPageInfoByTId/{TId}/{pageNum}/{pageSize}")
    public PageInfo<ProSet> getPageInfoByTId(@PathVariable("TId") Integer TId,@PathVariable("pageNum") Integer pageNum, @PathVariable("pageSize") Integer pageSize){
//        System.out.println("========");
//        System.out.println("TId: " + TId);
//        System.out.println("pageNum: " + pageNum);
//        System.out.println("pageSize: " + pageSize);
//        System.out.println("========");
        return proSetService.getPageInfoByTId(TId, pageNum, pageSize);
    }






}
